package com.weather.common.utils;

import java.io.*;

/**
 * @author: htc
 * @date: Created in 15:41 2018/5/4.
 */
public class SerializeUtils {
    public static byte[] serialize(Object object) throws IOException {
        byte[] bytes = null;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(object);
        bytes = baos.toByteArray();
        baos.close();
        oos.close();
        return bytes;
    }

    public static Object deSerialize(byte[] bytes) throws IOException, ClassNotFoundException {
        Object object = null;
        ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bais);
        object = ois.readObject();
        return object;
    }
}
